package com.gitee.freakchicken.dbapi.gateway.filter;

import com.alibaba.fastjson.JSON;
import com.gitee.freakchicken.dbapi.basic.service.C_U4by72J2;
import com.gitee.freakchicken.dbapi.common.ResponseDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Component
@Slf4j
public class C_NAAbmx3U implements GlobalFilter, Ordered {

    @Autowired
    C_U4by72J2 gf_4gREPxm0;

    @Override
    public Mono<Void> filter(ServerWebExchange p_3lup13j8, GatewayFilterChain p_TjfjqynD) {
        ServerHttpRequest lf_VX1ooitE = p_3lup13j8.getRequest();
        ServerHttpResponse lf_asgyWdRh = p_3lup13j8.getResponse();
        String lf_WuxrDTDR = lf_VX1ooitE.getRemoteAddress().getHostString();
        if (!gf_4gREPxm0.m_OHjeOge8(lf_WuxrDTDR)) {
            log.info("ip forbidden : {}", lf_WuxrDTDR);
            String lf_zxVum4sQ = JSON.toJSONString(ResponseDto.fail("Illegal ip (" + lf_WuxrDTDR + "), access forbidden"));
            DataBuffer lf_bV6VC2KD = lf_asgyWdRh.bufferFactory().wrap(lf_zxVum4sQ.getBytes());
            return lf_asgyWdRh.writeWith(Mono.just(lf_bV6VC2KD));
        }
        return p_TjfjqynD.filter(p_3lup13j8);
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
